﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace sieuthi
{
    public partial class hoadon : Form
    {
        private SqlDataAdapter da = new SqlDataAdapter();
        private SqlConnection conn = new SqlConnection(Threelayer.VO.core.connectionsring.ToString());
        private SqlCommand cmd = new SqlCommand();
        private DataTable dt = new DataTable("hoadon");
        Threelayer.VO.hoadonVO hd_vo;
        Threelayer.BUS.hoadonBUS hd_bus;
        public hoadon()
        {
            InitializeComponent();
        }

        private void hoadon_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sieuthiDataSet2.khachhang' table. You can move, or remove it, as needed.
            this.khachhangTableAdapter1.Fill(this.sieuthiDataSet2.khachhang);
            // TODO: This line of code loads data into the 'sieuthiDataSet2.nhanvien' table. You can move, or remove it, as needed.
            this.nhanvienTableAdapter1.Fill(this.sieuthiDataSet2.nhanvien);
            // TODO: This line of code loads data into the 'sieuthiDataSet.hoadon' table. You can move, or remove it, as needed.
            this.hoadonTableAdapter.Fill(this.sieuthiDataSet.hoadon);
            //hd_binding();
        }

            private void hd_binding()
        {

            box_giahh.DataBindings.Clear();
            box_giahh.DataBindings.Add("text", dataGridchitiet.DataSource, "giahh");
            box_hd.DataBindings.Clear();
            box_hd.DataBindings.Add("text", dataGridchitiet.DataSource, "mahd");
            box_kh.DataBindings.Clear();
            box_kh.DataBindings.Add("text", dataGridchitiet.DataSource, "kh");
            Box_manv.DataBindings.Clear();
            Box_manv.DataBindings.Add("text", dataGridchitiet.DataSource, "nv");
            box_ngay.DataBindings.Clear();
            box_ngay.DataBindings.Add("text", dataGridchitiet.DataSource, "ngay");

        }
            private void data_hoadon()
            {
                hd_vo = new Threelayer.VO.hoadonVO();
                hd_vo.GiaHh = box_giahh.Text;
                hd_vo.Kh = box_kh.Text;
                hd_vo.MaHd = box_hd.Text;
                hd_vo.Ngay = Convert.ToDateTime(box_ngay.Text);
                hd_vo.Nv = Box_manv.Text;
            }

            private void bt_hoadon_them_Click(object sender, EventArgs e)
            {
                data_hoadon();
                hd_bus = new Threelayer.BUS.hoadonBUS();
                hd_bus.hoadon_them(hd_vo);
                hoadon_Load(sender, e);
            }

            private void bt_hoadon_sua_Click(object sender, EventArgs e)
            {
                data_hoadon();
                hd_bus = new Threelayer.BUS.hoadonBUS();
                hd_bus.hoadon_sua(hd_vo);
                hoadon_Load(sender, e);
            }

            private void bt_hoadon_xoa_Click(object sender, EventArgs e)
            {
                data_hoadon();
                hd_bus = new Threelayer.BUS.hoadonBUS();
                hd_bus.hoadon_xoa(box_hoadon_timkiem.Text);
                hoadon_Load(sender, e);
            }

            private void bt_hoadon_timkiem_Click(object sender, EventArgs e)
            {
                dt.Clear();
                cmd.Dispose();
                cmd.Parameters.Clear();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                conn.Open();
                cmd.CommandText = "hoadon_timkiem";
                cmd.Parameters.Add("@makh", SqlDbType.NVarChar, 200).Value = box_hoadon_timkiem.Text;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                cmd.ExecuteNonQuery();
                da.Fill(dt);
                dataGridchitiet.DataSource = dt;
                conn.Close();
            }

    }
}
